<?
session_start();
if(!session_is_registered("myusername")){
    header("location:index.php");
}
else{
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
        <title>Kartapuce - Projet BDD FPMs >> Aide</title>
        <link rel="stylesheet" href="./mystyle.css" type="text/css" media="screen" />
    </head>
    <body>
        <small>
            <b>Logged as:
                <?
                session_start();
                print $myusername;
                ?>
                <A HREF="./logout.php">Log out</A>

            </b>
        </small>

        <div id="conteneur" align="center" class="conteneur">
            <div align="center" class="conteneurdessus">
                <img src="img/banner.png" width="600" height="185" alt="banner" border="0"/>
            </div>
        </div>
        <center>
            <div id="conteneurdessus" align="center" class="conteneurdessus">
                <table border="0" cellspacing="10">
                    <td>
                        <A HREF="./boutique.php"><img src="img/boutique.png" width="138" height="39" alt="boutique" border="0"/>
                        </A>
                    </td>
                    <td>
                        <A HREF="./compte.php"><img src="img/compte.png" width="138" height="39" alt="compte" border="0"/>
                        </A>
                    </td>
                    <td>
                        <A HREF="./commandes.php"><img src="img/commandes.png" width="138" height="39" alt="commandes" border="0"/>
                        </A>
                    </td>
                    <td>
                        <A HREF="./panier.php"><img src="img/panier.png" width="138" height="39" alt="panier" border="0"/>
                        </A>
                    </td>
                    <td>
                        <A HREF="./accueil.php"><img src="img/accueil.png" width="138" height="39" alt="accueil" border="0"/>
                        </A>
                    </td>
                </table>

            </div>
            <div id='colonne1' align='left' class='colonnem'>
            <?
            include 'connect_db.php';
/*
            $sql=   "SELECT db_cart.cartes_idcarte as 'idcarte',
                            db_cartes.description as 'description',
                            db_cartes.prix_indique as 'price',
                            db_cart.qty as 'qty',db_cart.qty*db_cartes.prix_indique as 'total'
                    FROM db_cart
                    INNER JOIN db_cartes ON db_cart.cartes_idcarte=db_cartes.idcarte
                    WHERE db_cart.clients_email='".$myusername."'";
 * */
            $sql=   "SELECT db_cart.cartes_idcarte as 'idcarte',
                            db_cartes.description as 'description',
                            db_cartes.prix_indique as 'price',
                            SUM(db_cart.qty) as 'qty',SUM(db_cart.qty*db_cartes.prix_indique) as 'total'
                    FROM db_cart
                    INNER JOIN db_cartes ON db_cart.cartes_idcarte=db_cartes.idcarte
                    WHERE db_cart.clients_email='".$myusername."'
                    GROUP BY db_cart.cartes_idcarte";

            //echo $sql;
            $result=mysql_query($sql);

            echo "<form name=form2 method=post action=action_panier.php>";

            echo '<TABLE BORDER=1>';
            echo '<TR><TD><b>IDcarte</b></TD><TD><b>Description</b></TD><TD><b>Prix unitaire(EUR)</b></TD><TD><b>Quantité désirée</b></TD><TD><b>Total</b></TD></TR>';
            while($tableau=mysql_fetch_array($result,MYSQL_ASSOC)){
                echo '<TR><TD>',$tableau['idcarte'],'</TD><TD>',$tableau['description'],'</TD><TD>',$tableau['price'],'</TD><TD>',$tableau['qty'],'</TD><TD>',$tableau['total'],'</TD></TR>';

            }
            $sql    =   "SELECT sum(db_cart.qty*db_cartes.prix_indique) as 'total'
                            FROM db_cart 
                            INNER JOIN db_cartes ON db_cart.cartes_idcarte=db_cartes.idcarte
                            WHERE db_cart.clients_email='".$myusername."'";
            $result=mysql_query($sql);
            $tableau=mysql_fetch_array($result,MYSQL_ASSOC);
            
            echo '<TR><TD><b>TOTAL</b></TD><TD>&nbsp</TD><TD>&nbsp</TD><TD>&nbsp</TD><TD><b>',$tableau['total'],'</b></TD></TR>';
            echo '</TABLE>';
            echo '<select name=action>
                                <option>Commander le panier</option>
                                <option>Vider le panier</option>
                    </select>';
            echo '<input type="submit" name="Submit" value="Action!">';
            echo "</form>";

            mysql_close($link);

            ?>
            </div>
        </center>
    </body>
</html>